class_name PlayerStateMachine extends Node

var stateList: Array[State]=[]
var prevState: String= ""
var prevOrientation:String

func _ready() -> void:
	var list= get_children()
	for item in list:
		if item is State:
			stateList.push_back(item)
	pass

func updateState(player:Player,stateName:String)->void:
	if player.currState==null: player.currState=stateList[0]
	if stateName==null||(player.currState.getName()==stateName&&player.getOrientation()==prevOrientation): return
	prevOrientation=player.getOrientation()
	player.currState.exit(player)
	for state in stateList:
		if state.getName() == stateName:
			player.currState= state
			state.enter(player)
			break
	pass
